﻿#include "precomp.h"
#include <QApplication>
#include <QTextCodec>
#include <QDateTime>
#include "jstylesheet.h"
#include "jsqldatamgr.h"
#include "mainwindow.h"

int main(int argc, char **argv)
{
    QApplication app(argc, argv);

    // textcodec
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
#if QT_VERSION < 0x050000
    QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
    QTextCodec::setCodecForCStrins(QTextCodec::codecForLocale());
#endif
    app.setApplicationName("curve maker");
    app.setApplicationDisplayName(QStringLiteral("曲线图制作软件"));
    app.setApplicationVersion("1.0.0");
    app.setWindowIcon(QIcon(QApplication::applicationDirPath()
                            .append("/images/logo.png")));

    app.setFont(QFont("Microsoft Yahei", 10));

    JWidgetsCore::instance()->init();

    qsrand((uint)QDateTime::currentDateTime().toMSecsSinceEpoch());

    // 记载系统语言翻译器
    if (!JWidgetsCore::instance()->loadSystemLang()) {
        qDebug() << "loading system language translator failure!";
    }

    // stylesheet
#ifdef J_HIGH_RESOLUTION
    app.setStyleSheet(JStyleSheet::styleSheet("default"));
#else
    app.setStyleSheet(JStyleSheet::styleSheet("default-normal"));
#endif

    // install log-handler
#ifdef APP_LOG
    //JLogManager::installMessageHandler();
    //JLogManager::setLogType(JLogManager::LogFile);
#endif

    //
    JSqlTableMgr::instance()->loadConfig(QApplication::applicationDirPath()
                                         .append("/../config/config.xml"));

#if 1
    JMyExcel::instance();
#endif

    // splas screen
    MainWindow *mainWindow = new MainWindow();
    mainWindow->showMaximized();

    return app.exec();
}
